package com.jz.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * @Description: 自定义资源映射
 * <p>
 * 设置虚拟路径，访问绝对路径下资源
 * </p>
 * @author: Yangxf
 * @date: 2019/4/17 18:17
 */
@Configuration
public class WebConfigurer extends WebMvcConfigurerAdapter {

    private static final Logger logger = LoggerFactory.getLogger(WebConfigurer.class);
    @Value("${config.file.filePath}")
    private String filePath;
    @Value("${config.file.resourceHandler}")
    private String resourceHandler;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        String s = "file:///" + filePath;
        logger.info("=========静态资源映射位置【{}】=============", s);
        registry.addResourceHandler(resourceHandler).addResourceLocations(s);
    }
}